package com.tanhua.dubbo.db.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.db.mappers.UserMapper;
import com.tanhua.model.db.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;


@DubboService
public class UserApiIpml implements UserApi  {


    @Autowired
    private UserMapper userMapper;

    //根据手机号查询用户
    @Override
    public User findByMobile(String mobile) {
        QueryWrapper<User> wrapper=new QueryWrapper<>();
        wrapper.eq("mobile",mobile);
        User user = userMapper.selectOne(wrapper);
        return user;
    }

    @Override
    public Long save(User user) {

        userMapper.insert(user);
        Long id = user.getId();
        return id;
    }

    ////修改手机号 - 3 保存
    @Override
    public void updateMobile(User user) {
        userMapper.updateById(user);
    }

    //根据id查询用户
    public User findById(Long id) {

        return userMapper.selectById(id);
    }

   //更新
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public Integer count() {
        Integer integer = userMapper.selectCount(null);

        return integer;
    }
}
